/**
 * 动态规划，难点在初始化dp时，初始化一个最大值+1
 * @param {number[]} coins
 * @param {number} amount
 * @return {number}
 */
var coinChange = function (coins, amount) {
    let dp = new Array(amount + 1).fill(amount + 1);
    dp[0] = 0;

    for (let i = 0; i < coins.length; i++) {
        for (let j = coins[i]; j <= amount; j++) {
            dp[j] = Math.min(dp[j], 1 + dp[j - coins[i]])
        }
    }
    if(dp[amount] === amount + 1){
        return -1
    }else{
        return dp[amount]
    }
};